EntityAIHuman = class(EntityAI)

function EntityAIHuman:init(entity)
    EntityAI.init(self,entity)
    self.walkSpeedOffs = 0
    self.walkSpeedOffsA = 0
    self.entity.yRot = math.random() * math.pi * 2
    self.timeOffs = math.random() * 1239813
    self.speed = 1
    self.rotA = (math.random() + 1) * 0.01
    self.moveSpeedScale = 1
end

function EntityAIHuman:getMoveDirection()
    return math.sin(self.entity.yRot) * self.moveSpeedScale,math.cos(self.entity.yRot) * self.moveSpeedScale
end

function EntityAIHuman:AIProcessMoving()
    if self.entity.inWater then
        if self.entity.horizontalCollision or math.random() < 0.2 then
            self.entity:jumpInLiquid()
        end
    elseif self.entity.inLava then
        if self.entity.horizontalCollision or math.random() < 0.5 then
            self.entity:jumpInLiquid()
        end
    else
        if self.entity.onGround and (self.entity.horizontalCollision or math.random() < 0.005) then
            self.entity:jumpOnGround()
        end
    end
end

function EntityAIHuman:AIProcessAfterMoving()
    -- 岩浆扣血
    if self.inLava then
        self.health = self.health - 0.1
    end
end

function EntityAIHuman:AIProcessBeforeMoving()
    self.entity.yRot = self.entity.yRot + self.rotA * 0.1
    self.rotA = self.rotA * 0.95
    self.rotA = self.rotA + (math.random() - math.random()) * math.random() * math.random() * math.pi / 4
    self.walkSpeedOffs = self.walkSpeedOffs + self.walkSpeedOffsA * 0.05
    self.walkSpeedOffsA = self.walkSpeedOffsA * 0.99
    self.walkSpeedOffsA = self.walkSpeedOffsA + (math.random() - math.random()) * math.random() * math.pi / 4
    
    self.moveSpeedScale = (1 + math.sin(self.walkSpeedOffs) * 0.2)
end

function EntityAIHuman:AIProcessBody(model)
    local time = timer:getTime() / (self.speed * 0.1) + self.timeOffs
    
    model.head.yRot = (math.sin(time * 0.04) * 0.5)
    model.head.xRot = (math.sin(time * 0.1) * 0.4)

    model.arm0.xRot = (math.sin(time * 0.6662 + math.pi) * 1)
    model.arm0.zRot = ((math.sin(time * 0.2312) + 1) * 0.1)

    model.arm1.xRot = (math.sin(time * 0.6662) * 1)
    model.arm1.zRot = ((math.sin(time * 0.2812) - 1) * 0.1)

    model.leg0.xRot = (math.sin(time * 0.6662) * 0.8)
    model.leg1.xRot = (math.sin(time * 0.6662 + math.pi) * 0.8)
end
